﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Json;
using System.Web;
using System.Net;

namespace FlickrGrabbr.Model
{
    class FlickrFetcher
    {
        private const string FlickrAPIKey = "ee5e816b3d183e992367b2c0f4e1d9ac";

        public static async Task<JsonValue> ExecuteFlickrFetch(string query)
        {
            query = String.Format("{0}&format=json&nojsoncallback=1&api_key={1}", query, FlickrAPIKey);
            WebClient webClient = new WebClient();
            string jsonString = await webClient.DownloadStringTaskAsync(query);
            JsonValue value = JsonValue.Parse(jsonString);
            
            return value;
        }

        public static async Task<JsonValue> TopPlaces()
        {
            string request = @"http://api.flickr.com/services/rest/?user_id=48247111@N07&format=json&nojsoncallback=1&extras=original_format,tags,description,geo,date_upload,owner_name&page=1&method=flickr.photos.search";
            return await ExecuteFlickrFetch(request);
        }
    }
}
